/*
 * ----------------------------------------------------------------------------
 * File Name: Rotate right
 * Author: Aeriff
 * Date Created: 2025.3.5
 * Last Modified: 2025.3.5
 * Description: rotate right
 * ----------------------------------------------------------------------------
*/

`timescale 1ns/1ps

module Rotate_Right (
    input [31:0] ror_src1,
    input [31:0] ror_src2,
    
    output [31:0] ror_result
);

    wire [4:0] shf;
    assign shf = ror_src1[4:0];
    wire [1:0] shf_1_0;
    wire [1:0] shf_3_2;
    assign shf_1_0 = shf[1:0];
    assign shf_3_2 = shf[3:2];

    wire [31:0] ro1;
    wire [31:0] ro2;


    assign ro1 = {32{shf_1_0 == 2'b00}} & ror_src2
               | {32{shf_1_0 == 2'b01}} & {ror_src2[0], ror_src2[31:1]}
               | {32{shf_1_0 == 2'b10}} & {ror_src2[1:0], ror_src2[31:2]}
               | {32{shf_1_0 == 2'b11}} & {ror_src2[2:0], ror_src2[31:3]};

    assign ro2 = {32{shf_3_2 == 2'b00}} & ro1                  
               | {32{shf_3_2 == 2'b01}} & {ro1[3:0], ro1[31:4]} 
               | {32{shf_3_2 == 2'b10}} & {ro1[7:0], ro1[31:8]} 
               | {32{shf_3_2 == 2'b11}} & {ro1[11:0], ro1[31:12]}; 

    assign ror_result = shf[4] ? {ro2[15:0], ro2[31:16]} : ro2;

    
endmodule